package cn.iocoder.yudao.module.controller;

import cn.iocoder.yudao.module.VO.ClazzVo;
import cn.iocoder.yudao.module.pojo.Clazz;
import cn.iocoder.yudao.module.pojo.Student;
import cn.iocoder.yudao.module.service.ClassService;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.annotation.security.PermitAll;
import java.util.List;

@RestController
@Slf4j
@Tag(name="班级信息管理")
@RequestMapping("/admin-api/edu/class")
public class ClassController {
    @Autowired
    private ClassService classService;



    @PermitAll
    @GetMapping("getClass")
    @Operation(summary = "获取班级基本信息")
    public CommonResult<Clazz> getClassById(Long id) {
        Clazz clazz1 = classService.findById(id);
        return CommonResult.success(clazz1);
    }
    @PermitAll
    @GetMapping("getStudentList")
    @Operation(summary = "获取班级学生列表")
    public CommonResult<List<Student>> getStudents(Long id) {
        List<Student> all = classService.findAllStudentByClassId(id);
        return CommonResult.success(all);
    }
    @PermitAll
    @PutMapping("updateClass")
    @Operation(summary = "更改班级基本信息")
    public CommonResult updateClass(@RequestBody ClazzVo clazz){
        classService.update(clazz);
        return CommonResult.success("true");
    }
    @PermitAll
    @PostMapping("saveClass")
    @Operation(summary = "新增班级基本信息")
    public CommonResult saveClass(@RequestBody ClazzVo clazz){
        classService.save(clazz);
        return CommonResult.success("true");
    }
    @PermitAll
    @DeleteMapping ("deleteClass")
    @Operation(summary = "删除班级基本信息")
    public CommonResult deleteClass(@RequestBody ClazzVo clazz){
        classService.delete(clazz);
        return CommonResult.success("true");
    }
}
